// Карточка во входящих
package dialogs
{
	import Classes.pi_events;
	import Classes.pi_images;
	
	import UIFree.ObjectEvent;
	import UIFree.controls.uif_label;
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import components.uif_cross;
	
	import editor.*;
	
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;

	public class pi_cardItem extends uif_ecomponent {
	    
		protected var _cardData: Object;
		protected var _cardPreview: pi_source;
		 
		public function pi_cardItem(parent:uif_component, a_data:Object , 
									ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, delButton: Boolean=false) {
			super(parent, ax, ay, awidth, aheight, 'cardItem');
			_cardData = a_data;
			var inner: Rectangle = getInner();
			inner.height = inner.height / 3 * 2;
			
			if (_cardData && _cardData.params && pi_data.infoFromID(a_data.params.cardID)) {
				_cardPreview = new pi_source(this, inner.x + 45, inner.y, 90, inner.height);
				_cardPreview.loadSource(pi_data.infoFromID(a_data.params.cardID).preview);
				_cardPreview.buttonMode 	= true;
				_cardPreview.mouseChildren 	= false;
/*				_cardPreview.addEventListener(MouseEvent.CLICK, doRelease);*/
				
				inner = getInner();
				inner.height = inner.height / 6;
				with (new uif_label(this, inner.x, inner.y + _cardPreview.height, inner.width, inner.height, 'cardAutor')) {
					text = _cardData.name;
				}
				inner.y += inner.height;
				with (new uif_label(this, inner.x, inner.y + _cardPreview.height, inner.width, inner.height, 'cardInfo')) {
					text = _cardData.time;
				}
				if (_cardData.received == 0) {
					with (addChild(new pi_images.c_new())) {
						x = 5;
					}
				}
				inner = getInner();
				var _userIcon: pi_source = new pi_source(this, inner.x + 30, inner.y, 60, 60, 'editor');
				_userIcon.loadSource(a_data.user.pic_small);
				
				if (delButton) {
					var del: uif_cross = new uif_cross(this, inner.x + inner.width - 20, inner.y, 20, 20, 'delButton');
					del.addEventListener(MouseEvent.CLICK, doDelClick);
				}
			}
		}
		
		public function doDelClick(e: MouseEvent): void {
			app.dispatchEvent(new ObjectEvent(pi_events.DELETECARD, _cardData));
			e.stopPropagation();
		}
		
		public function get cardData(): Object {
			return _cardData;
		}
		
	}
}